<?php
include_once 'file_manager.php';

$file = File_Manager::getInstance ();

$urlPhoto = $_GET['url'];

$curl = curl_init ( $urlPhoto );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_FAILONERROR, true );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $curl, CURLOPT_HTTPHEADER, array ("Authorization: GoogleLogin auth=" . $file->getToken () ) );

if (curl_exec ( $curl ) === false) {
	echo 'Curl error: ' . curl_error ( $curl );
	die ();
}

$response = curl_multi_getcontent ( $curl );
curl_close ( $curl );

$img = imagecreatefromstring ( $response );
header ( 'Content-Type: image/png' );
imagepng ( $img );
imagedestroy ( $img );

/*
//crear una variable para meterle contenido
$fp = fopen("var://myvar", "r+");

fwrite($fp, $response);
rewind($fp);
fclose($fp);
*/
//header("Content-type: image/png");
//print_r($myvar);
//echo $myvar;

/*
header("Content-type: image/png");
$im = @imagecreate(110, 100);
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  $response, $text_color);
imagepng($im);
*/
/*
$string = "Hola mundo!";
// tamaño de la imagen
$im = imagecreate(100, 30);

// fondo blanco y texto azul
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// escribimos el texto en la parte superior-izquierda
imagestring($im, 5, 0, 0, $string, $textcolor);

// mostrar la imagen
header("Content-type: image/png");
imagepng($im);
*/
